package com.jz.community.moduleshoppingguide.neighbor.task;

import android.app.Activity;

import com.jz.community.basecomm.constant.Constant;
import com.jz.community.basecomm.net.OkHttpUtil;
import com.jz.community.basecomm.task.ITaskCallbackListener;
import com.jz.community.basecomm.task.RxTask;
import com.jz.community.basecomm.utils.JsonUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.commview.view.widget.ProgressDialogManager;
import com.jz.community.moduleshoppingguide.neighbor.bean.AlreadyAddCircleBean;

import java.util.HashMap;

public class CircleMegTask extends RxTask<String, Integer, AlreadyAddCircleBean> {


    private Activity activity;
    private ITaskCallbackListener taskListener;

    public CircleMegTask(Activity activity,
                         ITaskCallbackListener taskListener) {
        super(activity);
        this.activity = activity;
        this.taskListener = taskListener;
    }

    @Override
    protected AlreadyAddCircleBean doInBackground(String... strings) {
        String result = OkHttpUtil.put(Constant.CIRCLES_MSG + "/" + strings[0], getParam(strings[1], strings[2]));
        AlreadyAddCircleBean circleBean = null;
        if (!Preconditions.isNullOrEmpty(result)) {
            circleBean = JsonUtils.parseObject(result, AlreadyAddCircleBean.class);
        }
        return circleBean;
    }

    @Override
    protected void onPostExecute(AlreadyAddCircleBean result) {
        // 执行结果回调函数
        taskListener.doTaskComplete(result);
        ProgressDialogManager.dismissProgressDialog();
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        ProgressDialogManager.showDialog(activity);
        super.onPreExecute();
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
    }

    private HashMap<String, Object> getParam(String lat, String lon) {
        HashMap<String, Object> param = new HashMap<>();
        param.put("lat", lat);
        param.put("lon", lon);
        return param;
    }
}
